﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Class_Entity;
using BussinessObject;
using System.Data;
using System.Data.SqlClient;

public partial class WebApplication_ADAddLiquidFilling : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }



    protected void btSubmit_Click(object sender, EventArgs e)
    {
        LiquidFilling li = new LiquidFilling();
        BOProducts bo = new BOProducts();

        // fill information into object li

        li.Model = txtModel.Text.Trim();
        li.AirPressure =Convert.ToInt32(txtAirP.Text.Trim());
        li.AirVolume = Convert.ToInt32(txtAirV.Text.Trim());
        li.FillingSpeed = Convert.ToInt32(txtFillS.Text.Trim());
        li.Image = "~\\WebApplication\\images\\" + FileUploadImage.FileName;
        li.FillingRangen = Convert.ToInt32(txtFillR.Text.Trim());

        FileUploadImage.SaveAs(Server.MapPath("~\\WebApplication\\images\\" + FileUploadImage.FileName));

        // check if validation are true then add to database

        if (Session["a"] == null)
        {
            bo.Add_LiquidFilling(li);
            HttpContext.Current.Response.Write("<script type='text/javascript'>alert('" + "Add Successfully ..." + "');window.location.href='ADLiquidFilling.aspx';</script>");


        }
    }



    protected void btReset_Click(object sender, EventArgs e)
    {
        resetAll();
    }

    private void resetAll()
    {
        txtModel.Text = "";
        txtAirP.Text = "";
        txtAirV.Text = "";
        txtFillR.Text = "";
        txtFillS.Text = "";

    }

    // check if model name exits or not

    protected void txtModel_TextChanged(object sender, EventArgs e)
    {
        LiquidFilling li = new LiquidFilling();
        BOProducts bo = new BOProducts();
        DataSet ds = bo.Load_LiquidFilling(li);
        DataTable dt = ds.Tables[0];
        Label1.Text = "";
        Session["a"] = null;

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (txtModel.Text.Trim() == dt.Rows[i]["Model"].ToString())
            {
                Session["a"] = 1;
                Label1.Text = "Model already exits";
            }

        }
    }
}